#include<iostream.h>
void menu();

class stack
			 
			  private:
						 int element;
						 stack *next;
			  public:
						stack* push(stack*,int);
						stack* pop();
						void stack_display(stack*);
			  }*head,*tail;
stack* stack::push(stack* head,int key)
{
 stack *temp,*temp1;
 temp1=head;
 temp=new stack;
 temp->element=key;
 temp->next=NULL;
 if(head==NULL)
 head=temp;
 else
	 {
	  while(head->next!=NULL)
			  head=head->next;
	  head->next=temp;
	  head=temp1;
	  }
	 return head;
 }
stack* stack::pop()
 {
		  stack* temp1,*d;
		  temp1=head;
		  if(temp1==NULL)
			  cout<<"the stack is empty";
		  else if(temp1->next==NULL)
					    {
						head=NULL;
						delete temp1;
						}
		  else
		  {
				  while(temp1->next->next!=NULL)
						{
						  temp1=temp1->next;
						}
		  d=temp1->next;
		  temp1->next=NULL;
		  delete d;
			}
 return head;
 }


 void stack::stack_display(stack* head)
 {
 stack* temp;
 temp=head;
 if(temp!=NULL)
	{
	 while(temp->next!=NULL)
			{
			cout<<temp->element<<"  ";
			temp=temp->next;
			}
			cout<<temp->element;
			cout<<endl;
	 }
 else
	  cout<<"The Stack Is Empty\n";
 }

int main()
{
int c,x;
stack object;
head=NULL;
tail=NULL;
menu();
cin>>c;
while(c!=4)
		{
		switch(c)
				  {
				  case 1:
							cout<<"\n Enter Element :  ";
							cin>>x;
							head=object.push(head,x);
							break;
				  case 2:
							tail=object.pop();
							break;
				  case 3:
							cout<<"\n-----------------------------------\n";
							object.stack_display(head);
							cout<<"\n-----------------------------------\n";
							break;
				  default:
							cout<<"Pl Enter Your Choice.(1,2,3,4)--->";
				  }
		menu();
		cin>>c;
}
return 0;
}
 void menu()
 {
  cout<<"\n       main menu  \n";
  cout<<"____________________________";
  cout<<"\n1>Add Element to A Stack\n";
  cout<<"2>Del Element form Stack\n";
  cout<<"3>Display Element on Stack\n";
  cout<<"4>Exit\n";
 }